<?php $this->pageTitle = 'Manage Tickets'; ?>
<div class="main-title no-border clearfix">
	<h1 class="float-left">Tickets</h1>
	<div class="controls">
		<a id="submitTicket" class="link-button with-icon" href="<?php echo $this->createUrl('admin/create'); ?>">
			<img src="/images/icons/fugue/report--plus.png" />
			New Ticket
		</a>
	</div>
</div>
<div class="flat_area">
    <div id="ps-ticket-index" class="grid_16 relative">
		<div class="grid-filter-menu">
			<?php
			$items = array();
			if (!empty($ticketStatusTypes)) {
				foreach ($ticketStatusTypes as $ticketStatusType) {
					$items[] = array(
						'label' => $ticketStatusType->code . ' (' . $ticketStatusType->getTicketCountForCurrentAgency() . ')',
						'url' => $this->createUrl($this->route, array('ticket_status' => $ticketStatusType->code)),
						'active' => $ticket_status == $ticketStatusType->code,
					);
				}
				$this->widget('zii.widgets.CMenu', array(
					'items' => $items
				));
			}
			?>
		</div>
		<div id="ps-ticket-index" class="box">
			<h2 class="box_head grad_colour with-icon"><img width="16" height="16" src="/images/icons/fugue/folder.png" /><?php echo ucwords($ticket_status); ?> Tickets</h2>
				<?php
				
				$form=$this->beginWidget('CActiveForm', array(
						'enableAjaxValidation'=>true,
					)
				); 
				
				$this->widget('PsGridView', array(
					'id' => 'invoice-index-grid',
					'dataProvider' => $ticket->search(),
					'filter' => $ticket,
					'template' => '{items}{pager}{pagesize}',
					'htmlOptions' => array(
						'class' => 'grid-view grey'
					),
					'pagerCssClass' => 'pager float-right',
					'pagesizeCssClass' => 'pager-pagesize float-right',
					'columns' => array(
						array(
							'id'=>'autoId',
							'class'=>'CCheckBoxColumn',
							'selectableRows' => '10',
							'value' => '$data->ticket_code',
						),
						array(
							'header' => 'Date',
							'name' => 'create_time',
							'type' => 'date',
							'htmlOptions' => array('width' => 100),
						),
						array(
							'header' => '#',
							'type' => 'raw',
							'name' => 'ticket_code',
							'value' => 'CHtml::link("#" . $data->ticket_code, array("admin/view", "ticket_code" => $data->ticket_code), array("class" => "blue link"))',
							'htmlOptions' => array('width' => 50),
						),
						array(
							'name' => 'subject',
							'type' => 'raw',
							'value' => 'CHtml::link($data->subject, array("admin/view", "ticket_code" => $data->ticket_code), array("class" => "blue link"))',
						),
						/*
						array(
							'name' => 'current_status',
							'value' => '$data->current_status',
							'filter' => CHtml::listData(TicketStatusType::model()->findAll(), 'code', 'code'),
							'htmlOptions' => array('width' => 80),
						),*/
						array(
							'name' => 'ticket_type_id',
							'filter' => CHtml::listData(TicketType::model()->findAll(), 'id', 'name'),
							'value' => function ($data){
								echo TicketType::model()->findByPk($data->ticket_type_id)->name;
							},
							'htmlOptions' => array('width' => 80),
							
						),
						array(
							'header' => 'Reference #',
							'name' => 'reference',
							'value' => '$data->reference',
							'htmlOptions' => array('width' => 80),
						),
						array(
							'name' => 'ticket_source_id',
							'filter' => CHtml::listData(TicketSource::model()->findAll(), 'id', 'name'),
							'value' => function ($data){
								echo TicketSource::model()->findByPk($data->ticket_source_id)->name;
							},
							'htmlOptions' => array('width' => 80),
						),
						array(
							'header' => 'From',
							'name' => 'name',
							'htmlOptions' => array('width' => 200),
						),
						/*
						array(
							'header' => 'Last Response',
							'name' => 'last_response_time',
							'filter' => array('Not Responded' => 'Not Responded', 'Responded' => 'Responded'),
							'value' => '$data->getLastResponseDate()',
							'htmlOptions' => array('width' => 100),
						)*/
						array
							(
								'class'=>'CButtonColumn',
								'header' => 'Actions',
								'template'=>'{update}',
								'buttons'=>array
								(
									'update' => array
									(
										'url'=>'Yii::app()->createUrl("/tickets/admin/update", array("ticket_code"=>$data->ticket_code))',
									)
								),
							),
					)
				));
				echo CHtml::ajaxSubmitButton('Filter',array('/tickets/admin/ajaxupdate'), array(),array("style"=>"display:none;"));
				echo CHtml::ajaxSubmitButton('Close',array('/tickets/admin/ajaxupdate','act'=>'doClose'), array('success'=>'reloadGrid'),array('class'=>'buttonAdd','style'=>' margin-right:20px'));
				//echo CHtml::ajaxSubmitButton('In Activate',array('/banners/manageBanners/ajaxupdate','act'=>'doInactive'), array('success'=>'reloadGrid'),array('class'=>'buttonAdd','style'=>' margin-right:20px')); 
				echo CHtml::ajaxSubmitButton('Delete',array('/tickets/admin/ajaxupdate','act'=>'doDelete'), array('success'=>'reloadGrid'),array('class'=>'buttonAdd','style'=>' margin-right:20px'));
				//echo CHtml::ajaxSubmitButton('Update sort order',array('/banners/manageBanners/ajaxupdate','act'=>'doSortOrder'), array('success'=>'reloadGrid'),array('class'=>'buttonAdd','style'=>'border:0; margin-right:20px'));
				$this->endWidget();
				?>
		</div>
		<script>
			function reloadGrid(data) {
				$.fn.yiiGridView.update('invoice-index-grid');
			}
		</script>
    </div>
</div>
